/*
 * Copyright (c) gitee.com/jiandong001.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import hilog from '@ohos.hilog';
import { UIViewOperationQueue } from './UIViewOperationQueue';
import { ViewManagerRegistry } from './ViewManagerRegistry';
import { ReactContext } from '../bridge/ReactContext';
import { ViewManagerResolver } from './ViewManagerResolver';
import { EventDispatcher } from './events/EventDispatcher';
import { UIImplementation } from './UIImplementation';

import List from '@ohos.util.List';


/** Provides UIImplementation to use in {@link UIManagerModule}. */
//@Deprecated
export class UIImplementationProvider {
  private static readonly TAG = 'react UIImplementationProvider'
   public constructor() {}

//  public createUIImplementation(
//      reactContext: ReactContext,
////      viewManagerResolver: ViewManagerResolver,
////      eventDispatcher: EventDispatcher,
//      minTimeLeftInFrameForNonBatchedOperationMs: number): UIImplementation {
////    Systrace.beginSection(
////        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIImplementationProvider.createUIImplementation[1]");
//    //try {
//      return new UIImplementation(
//          reactContext,
////          viewManagerResolver,
////          eventDispatcher,
//          minTimeLeftInFrameForNonBatchedOperationMs);
//    //} finally {
//      //Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
//    //}
//  }
//
//  public UIImplementation createUIImplementation(
//      ReactApplicationContext reactContext,
//      List<ViewManager> viewManagerList,
//      EventDispatcher eventDispatcher,
//      int minTimeLeftInFrameForNonBatchedOperationMs) {
//    Systrace.beginSection(
//        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIImplementationProvider.createUIImplementation[2]");
//    try {
//      return new UIImplementation(
//          reactContext,
//          viewManagerList,
//          eventDispatcher,
//          minTimeLeftInFrameForNonBatchedOperationMs);
//    } finally {
//      Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
//    }
//  }

   createUIImplementation(
      reactContext: ReactContext,
      viewManagerRegistry: ViewManagerRegistry,
       eventDispatcher: EventDispatcher,
      minTimeLeftInFrameForNonBatchedOperationMs: number): UIImplementation {
//    Systrace.beginSection(
//        Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIImplementationProvider.createUIImplementation[3]");
    try {
      return new UIImplementation(
          reactContext,
          viewManagerRegistry,
          eventDispatcher,
        minTimeLeftInFrameForNonBatchedOperationMs);
    } catch (e: any) {
//      Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
        let error = e as Error
        hilog.error(0x0000, UIImplementationProvider.TAG,
          "UIImplementation error:" +
          "message: " + error.message +
          "stack: " + error.stack)
    }
  }
}
